package mapspinner.util;

public class ArrayUtils {
	public static class Shifter {
		public Shifter(final int xShift, final int zShift,
				final Object[][] array) {
			if (xShift > 0) {
				final Object[][] buf = new Object[xShift][];
				for (int x = 0; x < xShift; x++)
					buf[x] = array[x];
				System
						.arraycopy(array, xShift, array, 0, array.length
								- xShift);
				for (int x = 0; x < xShift; x++)
					array[array.length - x - 1] = buf[x];
			}
			if (xShift < 0) {
				final Object[][] buf = new Object[-xShift][];
				for (int x = 0; x < -xShift; x++)
					buf[x] = array[array.length - x - 1];
				System.arraycopy(array, 0, array, -xShift, array.length
						+ xShift);
				for (int x = 0; x < -xShift; x++)
					array[x] = buf[x];
			}
			if (zShift > 0)
				for (final Object[] row : array) {
					final Object[] buf = new Object[zShift];
					for (int z = 0; z < zShift; z++)
						buf[z] = row[z];
					System.arraycopy(row, zShift, row, 0, row.length - zShift);
					for (int z = 0; z < zShift; z++)
						row[array.length - z - 1] = buf[z];
				}
			if (zShift < 0)
				for (final Object[] row : array) {
					final Object[] buf = new Object[-zShift];
					for (int z = 0; z < -zShift; z++)
						buf[z] = row[array.length - z - 1];
					System.arraycopy(row, 0, row, -zShift, row.length + zShift);
					for (int z = 0; z < -zShift; z++)
						row[z] = buf[z];
				}
		}

		public void shift(final Object object, final int x, final int y) {

		}
	}

	public static class SpiralVisitor {
		public SpiralVisitor(final int n) {
			this(n, 0, 0);
		}

		public SpiralVisitor(final int n, final int start, final int stop) {
			int i, j, k, add = 0;

			if (n % 2 == 1) {
				visit(((n - 1) / 2), ((n - 1) / 2));
				add = 1;
			}
			for (i = n / 2 + add + start, j = n / 2 - 1 - start; i < n - stop; i++, j--) {
				for (k = j; k < i; k++)
					visit(j, k);

				for (k = j; k < i; k++)
					visit(k, i);

				for (k = i; k > j; k--)
					visit(i, k);

				for (k = i; k > j; k--)
					visit(k, j);
			}
		}

		public void visit(final int x, final int z) {

		}
	}
}
